<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<base href="<?php echo base_url(); ?>"/>
<title><?php echo $title; ?></title>
<link href="style/base.css" rel="stylesheet" type="text/css"/>
<link href="style/common.css" rel="stylesheet" type="text/css"/>
<link href="style/houtai.css" rel="stylesheet" type="text/css"/>
<link href="style/yindao.css" rel="stylesheet" type="text/css" />
<link href="style/my.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script src="js/organictabs.jquery.js"></script>
<script type="text/javascript" src="js/Common.js"></script>
<script type="text/javascript" src="js/Validation.js"></script>
<script type="text/javascript" src="jscript/WdatePicker.js"></script>
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
<!--[if IE 6]>
<script type="text/javascript" language="javascript" src="js/ie6/DD_belatedPNG_0.0.8a-min.js"></script>
<script type="text/javascript" language="javascript">
    DD_belatedPNG.fix('.logo img,.footer_logo img');
</script>
<![endif]-->
<script type="text/javascript">
$(function(){
    initSelected();
    loadCity("ddlLiveProvince","ddlLiveCity");
    loadCity("ddlOriProvince","ddlOriCity");
    $("#ddlLiveProvince").bind("change",function(){
        loadCity("ddlLiveProvince","ddlLiveCity");
    });
    $("#ddlOriProvince").bind("change",function(){
        loadCity("ddlOriProvince","ddlOriCity");
    });
    $("#txtRealName").bind("blur",checkRealName);
    $("#txtBirthDay").bind("blur",checkBirthday);
    $("#ddlLiveProvince,#ddlLiveCity").bind("blur",checkLive);
    $("#ddlOriProvince,#ddlOriCity").bind("blur",checkOri);
    $("#txtPhone").bind("blur",checkPhone);
    $("#txtQQ").bind("blur",checkQQ);
    $("#btnSave").bind("click",save);
    $("#imgUpLoad").bind("click",choiceHeadImg);
    $("#fileHead").bind("change",loadImg);
    bindSubmit();
    loadUserInfo();
});
function bindSubmit(){
    var options = {
        beforeSubmit:  showRequest,  //提交前处理
        success:       showResponse,  //处理完成
        resetForm: false,
        dataType:  'json'
    };

    $('#formArchive').submit(function() {

        $(this).ajaxSubmit(options);
        return false;
    });
}
function showRequest(formData, jqForm, options) {
    return true;
}

function showResponse(data, statusText)  {
    if(data.ReturnCode==1){
        $("#imgHead").attr("src",data.src);
        saveArchiveHead(data.src);
    }else{
        SetError("spanImgTip",data.Msg);
    }
    return false;
}
function saveArchiveHead(src){
    var params = {headurl:src};
    $.ajax({
        type:"post",
        url:"index.php/login/saveArchiveHead",
        dataType:"json",
        data:params,
        success:function(data){

        }
    });
}
function loadUserInfo(){
    $.ajax({
        type:"post",
        url:"index.php/login/getUserInfo",
        dataType:"json",
        success:function(data){
            $("#txtRealName").val(data.realname);
            $("#txtBirthDay").val(data.birthday);
            $("#ddlLiveProvince").val(data.provinceid);
            loadCity("ddlLiveProvince","ddlLiveCity");
            $("#ddlLiveCity").val(data.cityid);
            $("#ddlOriProvince").val(data.jgprovinceid);
            loadCity("ddlOriProvince","ddlOriCity");
            $("#ddlOriCity").val(data.jgcityid);
            $("#txtPhone").val(data.phone);
            $("#txtQQ").val(data.qq);
            if(!IsEmpty(data.headurl)){
                $("#imgHead").attr("src",data.headurl);
            }
            if(!IsEmpty(data.sex)){
                if(data.sex=="男"){
                    $("#sex_male").trigger("click");
                }else{
                    $("#sex_female").trigger("click");
                }
            }
        }
    });
}
function loadCity(p,c){
    var provinceid = $("#"+p).val();
    $("#"+c).html("<option value=''>请选择...</option>");
    if(IsEmpty(provinceid)){
        return;
    }

    var url = "index.php/city/getByProvinceId";
    var params = {provinceid:provinceid};
    $.ajax({
        type:"post",
        url:url,
        dataType:"html",
        data:params,
        async:false,
        success:function(data){
            $("#"+c).append(data);
        }
    });
}
function save(){
    if(checkRealName()==false)
        return;
    if(checkBirthday()==false)
        return;
    if(checkLive()==false)
        return;
    if(checkOri()==false)
        return;
    if(checkPhone()==false)
        return;
    if(checkQQ()==false)
        return;
    var sex = $("a[id^='sex_'][class='seled']:first").text();
    var realName = $("#txtRealName").val();
    var birthday = $("#txtBirthDay").val();
    var provinceid = $("#ddlLiveProvince").val();
    var cityid = $("#ddlLiveCity").val();
    var jgprovinceid = $("#ddlOriProvince").val();
    var jgcityid = $("#ddlOriCity").val();
    var phone = $("#txtPhone").val();
    var qq = $("#txtQQ").val();
    var params = {
        sex:sex,
        realname:realName,
        birthday:birthday,
        provinceid:provinceid,
        cityid:cityid,
        jgprovinceid:jgprovinceid,
        jgcityid:jgcityid,
        phone:phone,
        qq:qq
    };

    var url = "index.php/login/saveArchiveOne";
    $.ajax({
        type:"post",
        url:url,
        dataType:"json",
        data:params,
        success:function(data){
            if(data.ReturnCode==1){
                if($("#btnSave").attr("src")=="images/bc_inp.jpg"){
                    alert('保存成功');
                    window.location="<?php echo base_url()?>index.php/manage/userinfo";
                }
                else{
                    window.location="<?php echo base_url()?>index.php/login/archivet"
                }
            }else{
                alert('保存失败');
            }
        }
    });
}
function checkRealName(){
    var realName = $("#txtRealName").val();
    if(IsEmpty(realName)){
        SetError("txtRealName","请输入真实姓名");
        return false;
    }
    var len = realName.length;
    if(len<2 || len>20){
        SetError("txtRealName","姓名长度为 2 到 20 个字符");
        return false;
    }
    SetOK("txtRealName");
    return true;
}
function checkBirthday(){
    var birthDay = $("#txtBirthDay").val();
    if(IsEmpty(birthDay)){
        SetError("txtBirthDay","请输入生日");
        return false;
    }
    var isok=true;
    var params = {birthday:birthDay};
    $.ajax({
        type:"post",
        url:"index.php/login/checkBirthDay",
        dataType:"json",
        data:params,
        success:function(data){
            if(data.ReturnCode!=1){
                isok=false;
                SetError("txtBirthDay",data.Msg);
            }
        }
    });
    if(isok==false)
        return false;
    SetOK("txtBirthDay");
    return true;
}
function checkLive(){
    var provinceid = $("#ddlLiveProvince").val();
    var cityid = $("#ddlLiveCity").val();
    if(IsEmpty(provinceid) || IsEmpty(cityid)){
        SetError("ddlLiveCity","请选择省市");
        return false;
    }
    SetOK("ddlLiveCity");
    return true;
}
function checkOri(){
    var provinceid = $("#ddlOriProvince").val();
    var cityid = $("#ddlOriCity").val();
    if(IsEmpty(provinceid) || IsEmpty(cityid)){
        SetError("ddlOriCity","请选择省市");
        return false;
    }
    SetOK("ddlOriCity");
    return true;
}
function checkPhone(){
    var phone = $("#txtPhone").val();
    if(IsEmpty(phone)){
        SetError("txtPhone","请输入手机号");
        return false;
    }
    if(!IsMobile(phone)){
        SetError("txtPhone","非有效手机号");
        return false;
    }

    SetOK("txtPhone");
    return true;
}
function checkQQ(){
    var qq = $("#txtQQ").val();
    if(IsEmpty(qq)){
        SetError("txtQQ","请输入QQ");
        return false;
    }
    var len = qq.length;
    if(len>20){
        SetError("txtQQ","长度位于1到20字符之间");
        return false;
    }

    SetOK("txtQQ");
    return true;
}
function choiceHeadImg(){
    $("#fileHead").trigger("click");
}
function loadImg(){
    ClearError("spanImgTip");
    var fileName = $("#fileHead").val();
    var ext=fileName.substr(fileName.indexOf(".")).toLowerCase();
    if(ext!=".gif" && ext!=".jpg" && ext!=".jpeg" && ext!=".png" && ext!=""){
        SetError("spanImgTip","图片格式无效");
        return;
    }
    if(!IsEmpty(fileName)){
        $("#formArchive").submit();
        return;
    }


    if(IsEmpty(fileName))
        $("#imgHead").attr("src","images/touxiang_img.jpg");
    else
        $("#imgHead").attr("src",src);
}
//初始化性别选择样式
function initSelected(){
    //选中filter下的所有a标签，为其添加hover方法，该方法有两个参数，分别是鼠标移上和移开所执行的函数。
    $("a[id^='sex_']").hover(
        function () {
            $(this).addClass("seling");
        },
        function () {
            $(this).removeClass("seling");
        }
    );
    //选中filter下所有的dt标签，并且为dt标签后面的第一个dd标签下的a标签添加样式seled。(感叹jquery的强大)
    $("a[id^='sex_']:first").attr("class", "seled"); /*注意：这儿应该是设置(attr)样式，而不是添加样式(addClass)，
     不然后面通过$("#filter1 a[class='seled']")访问不到class样式为seled的a标签。*/

    //为filter下的所有a标签添加单击事件
    $("a[id^='sex_']").click(function () {
        $(this).parents("div").children("a").each(function () {
            //下面三种方式效果相同（第三种写法的内部就是调用了find()函数，所以，第二、三种方法是等价的。）
            //$(this).children("div").children("a").removeClass("seled");
            //$(this).find("a").removeClass("seled");
            $(this).removeClass("seled");
        });

        $(this).attr("class", "seled");
    });
}
</script>
<body>
<?php
include 'header.php';
?>
<form id="formArchive" action="index.php/login/uploadImg" method="post"
      enctype="multipart/form-data">
    <!-- 01 开始 -->
    <div class="yindao_k">
        <?php
        if (! isset ( $ht )) {
            print "<div class='yindao_bt'>
							<img src='images/yindao_01.jpg' />
						</div>";
        }
        ?>

        <div class="jiben">
            <?php
            if(!isset($ht)){
                print "<div class='jiben_l'>
									<img id='imgHead' src='images/touxiang_img.jpg' width='125'
										height='125' />
									<div class='pt_20'>
										<span id='spanImgTip'></span>
									</div>
									<div class='pt_20'>
										<img id='imgUpLoad' name='imgUpLoad' class='link'
											src='images/sctx_inp.jpg' style='width: 130px; height: 30px' /> 
										<input	type='file' id='fileHead' name='mypic' style='display: none'>
									</div>
								</div>";
            }
            else{
                print "<div class='jiben_l'></div>";
            }
            ?>

            <div class="jiben_r">
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">性别</div>
                    </div>
                    <a id="sex_male" style="color: black; padding: 15px;">男</a> <a
                        id="sex_female" style="color: black; padding: 15px;">女</a>
                </div>
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">真实姓名</div>
                    </div>
                    <input id="txtRealName" style="width: 225px; height: 25px;"
                           type="text" />
                </div>
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">出生日期</div>
                    </div>
                    <input id="txtBirthDay"
                           onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
                           class="wdate" readonly="true" style="width: 225px; height: 25px;"
                           type="text" />
                </div>
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">所在城市</div>
                    </div>
                    <select id="ddlLiveProvince" style="width: 110px; height: 25px;">
                        <option value="">请选择...</option>
                        <?php
                        foreach ( $province as $key => $value ) {
                            print "<option value='$key'>$value</option>";
                        }
                        ?>
                    </select> <select id="ddlLiveCity"
                                      style="width: 110px; height: 25px;">

                    </select>
                </div>
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">籍贯城市</div>
                    </div>
                    <select id="ddlOriProvince" style="width: 110px; height: 25px;">
                        <option value="">请选择...</option>
                        <?php
                        foreach ( $province as $key => $value ) {
                            print "<option value='$key'>$value</option>";
                        }
                        ?>
                    </select> <select id="ddlOriCity"
                                      style="width: 110px; height: 25px;">

                    </select>
                </div>
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">联系电话</div>
                    </div>
                    <input id="txtPhone" style="width: 225px; height: 25px;"
                           type="text" />
                </div>
                <div class="mima">
                    <div class="mima_span">
                        <div class="right">QQ</div>
                    </div>
                    <input id="txtQQ" style="width: 225px; height: 25px;" type="text" />
                </div>
            </div>
        </div>

        <?php
        if (! isset ( $ht )) {
            print "<div class='filter_inp'>
								<img id='btnSave' src='images/bcxyb_inp.jpg' class='link' />
							</div>";
        } else {
            print "<div class='filter_inp'>
								<img id='btnSave' class='link' src='images/bc_inp.jpg'>
							</div>";
        }
        ?>
    </div>
    <!-- 01 结束 -->
</form>
<!-- 页脚 开始 -->
<?php include 'footer.php';?>
<!-- 页脚 结束 -->
</body>
</html>
